(* see also BuiltinPrimitive.ppg and BuiltinTypes.sml *)

datatype char     = _builtin datatype char
datatype string   = _builtin datatype string
datatype unit     = _builtin datatype unit
datatype ptr      = _builtin datatype ptr
datatype codeptr  = _builtin datatype codeptr
datatype exn      = _builtin datatype exn
datatype array    = _builtin datatype array
datatype vector   = _builtin datatype vector
datatype bool     = _builtin datatype bool
datatype list     = _builtin datatype list
datatype option   = _builtin datatype option
datatype ref      = _builtin datatype ref
datatype size     = _builtin datatype size

(* 2013-09-21 ohori moved tintInf, word8, real32, boxed to toplevel *)
datatype int8     = _builtin datatype int8
datatype int16    = _builtin datatype int16
datatype int32    = _builtin datatype int32
datatype int64    = _builtin datatype int64
datatype intInf   = _builtin datatype intInf
datatype largeInt = _builtin datatype intInf
datatype word8    = _builtin datatype word8
datatype word16   = _builtin datatype word16
datatype word32   = _builtin datatype word32
datatype word64   = _builtin datatype word64
datatype real32   = _builtin datatype real32
datatype real64   = _builtin datatype real64
datatype boxed    = _builtin datatype boxed
datatype contag   = _builtin datatype contag
datatype record   = _builtin datatype record

exception Bind
exception Match
exception Subscript
exception Size
exception Overflow
exception Div
exception Domain
exception Fail of string
exception Chr

val = = _builtin val Equal : ''a * ''a -> bool
val <> = _builtin val NotEqual : ''a * ''a -> bool

(* The followings are provided for defining the Basis Library. *)
structure SMLSharp_Builtin =
struct

  structure Array =
  struct
    val alloc_unsafe =
        _builtin val Array_alloc_unsafe
        : int32 -> 'a array
    val copy_unsafe =
        _builtin val Array_copy_unsafe
        : 'a array * int32 * 'a array * int32 * int32 -> unit
    val sub_unsafe =
        _builtin val Array_sub_unsafe
        : 'a array * int32 -> 'a
    val update_unsafe =
        _builtin val Array_update_unsafe
        : 'a array * int32 * 'a -> unit
    val alloc =
        _builtin val Array_alloc
        : int32 -> 'a array
    val copy =
        _builtin val Array_copy
        : {src: 'a array, dst: 'a array, di: int32} -> unit
    val length =
        _builtin val Array_length
        : 'a array -> int32
    val sub =
        _builtin val Array_sub
        : 'a array * int32 -> 'a
    val update =
        _builtin val Array_update
        : 'a array * int32 * 'a -> unit

    val castToWord8Array = _builtin val TypeCast : char array -> word8 array
  end

  structure Vector =
  struct
    val alloc =
        _builtin val Vector_alloc
        : int32 -> 'a vector
    val alloc_unsafe =
        _builtin val Vector_alloc_unsafe
        : int32 -> 'a vector
    val length =
        _builtin val Vector_length
        : 'a vector -> int32
    val sub =
        _builtin val Vector_sub
        : 'a vector * int32 -> 'a

    val castToArray = _builtin val TypeCast : 'a vector -> 'a array
  end

  structure String =
  struct
    val alloc =
        _builtin val String_alloc
        : int32 -> string
    val alloc_unsafe =
        _builtin val String_alloc_unsafe
        : int32 -> string
    val size =
        _builtin val String_size
        : string -> int32
    val sub =
        _builtin val String_sub
        : string * int32 -> char
    val identityEqual =
        _builtin val IdentityEqual
        : string * string -> bool

    val castToArray = _builtin val TypeCast : string -> char array
    val castToWord8Array = _builtin val TypeCast : string -> word8 array
    val castToBoxed = _builtin val TypeCast : string -> boxed
  end

  structure Real64 =
  struct
    val abs = _builtin val Real_abs : real64 -> real64
    val add = _builtin val Real_add : real64 * real64 -> real64
    val div = _builtin val Real_div : real64 * real64 -> real64
    val equal = _builtin val Real_equal : real64 * real64 -> bool
    val ueq = _builtin val Real_unorderedOrEqual : real64 * real64 -> bool
    val gt = _builtin val Real_gt : real64 * real64 -> bool
    val gteq = _builtin val Real_gteq : real64 * real64 -> bool
    val isNan = _builtin val Real_isNan : real64 -> bool
    val lt = _builtin val Real_lt : real64 * real64 -> bool
    val lteq = _builtin val Real_lteq : real64 * real64 -> bool
    val mul = _builtin val Real_mul : real64 * real64 -> real64
    val rem = _builtin val Real_rem : real64 * real64 -> real64
    val sub = _builtin val Real_sub : real64 * real64 -> real64
    val neg = _builtin val Real_neg : real64 -> real64
    val notEqual = _builtin val Real_notEqual : real64 * real64 -> bool
    val trunc = _builtin val Real_trunc : real64 -> int32
    val fromInt8 = _builtin val Real_fromInt : int8 -> real64
    val fromInt16 = _builtin val Real_fromInt : int16 -> real64
    val fromInt32 = _builtin val Real_fromInt : int32 -> real64
    val fromInt64 = _builtin val Real_fromInt : int64 -> real64
    val toInt8_unsafe = _builtin val Real_trunc_unsafe : real64 -> int8
    val toInt16_unsafe = _builtin val Real_trunc_unsafe : real64 -> int16
    val toInt32_unsafe = _builtin val Real_trunc_unsafe : real64 -> int32
    val toInt64_unsafe = _builtin val Real_trunc_unsafe : real64 -> int64
    val toWord8_unsafe = _builtin val Real_fptoui : real64 -> word8
    val toWord16_unsafe = _builtin val Real_fptoui : real64 -> word16
    val toWord32_unsafe = _builtin val Real_fptoui : real64 -> word32
    val toWord64_unsafe = _builtin val Real_fptoui : real64 -> word64
  end

  structure Real32 =
  struct
    val abs = _builtin val Real_abs : real32 -> real32
    val add = _builtin val Real_add : real32 * real32 -> real32
    val div = _builtin val Real_div : real32 * real32 -> real32
    val equal = _builtin val Real_equal : real32 * real32 -> bool
    val ueq = _builtin val Real_unorderedOrEqual : real32 * real32 -> bool
    val gt = _builtin val Real_gt : real32 * real32 -> bool
    val gteq = _builtin val Real_gteq : real32 * real32 -> bool
    val isNan = _builtin val Real_isNan : real32 -> bool
    val lt = _builtin val Real_lt : real32 * real32 -> bool
    val lteq = _builtin val Real_lteq : real32 * real32 -> bool
    val mul = _builtin val Real_mul : real32 * real32 -> real32
    val rem = _builtin val Real_rem : real32 * real32 -> real32
    val sub = _builtin val Real_sub : real32 * real32 -> real32
    val neg = _builtin val Real_neg : real32 -> real32
    val notEqual = _builtin val Real_notEqual : real32 * real32 -> bool
    val trunc = _builtin val Real_trunc : real32 -> int32
    val fromInt8 = _builtin val Real_fromInt : int8 -> real32
    val fromInt16 = _builtin val Real_fromInt : int16 -> real32
    val fromInt32 = _builtin val Real_fromInt : int32 -> real32
    val fromInt64 = _builtin val Real_fromInt : int64 -> real32
    val toInt8_unsafe = _builtin val Real_trunc_unsafe : real32 -> int8
    val toInt16_unsafe = _builtin val Real_trunc_unsafe : real32 -> int16
    val toInt32_unsafe = _builtin val Real_trunc_unsafe : real32 -> int32
    val toInt64_unsafe = _builtin val Real_trunc_unsafe : real32 -> int64
    val toWord8_unsafe = _builtin val Real_fptoui : real32 -> word8
    val toWord16_unsafe = _builtin val Real_fptoui : real32 -> word16
    val toWord32_unsafe = _builtin val Real_fptoui : real32 -> word32
    val toWord64_unsafe = _builtin val Real_fptoui : real32 -> word64
    val fromReal64 = _builtin val Real_fpext_fptrunc : real64 -> real32
    val toReal64 = _builtin val Real_fpext_fptrunc : real32 -> real64
  end

  structure Char =
  struct
    val chr = _builtin val Char_chr : int32 -> char
    val gt = _builtin val Char_gt : char * char -> bool
    val gteq = _builtin val Char_gteq : char * char -> bool
    val lt = _builtin val Char_lt : char * char -> bool
    val lteq = _builtin val Char_lteq : char * char -> bool
    val ord = _builtin val Char_ord : char -> int32

    val castToWord8 = _builtin val TypeCast : char -> word8
  end

  structure Int8 =
  struct
    val add_unsafe = _builtin val Int_add_unsafe : int8 * int8 -> int8
    val gt = _builtin val Int_gt : int8 * int8 -> bool
    val gteq = _builtin val Int_gteq : int8 * int8 -> bool
    val lt = _builtin val Int_lt : int8 * int8 -> bool
    val lteq = _builtin val Int_lteq : int8 * int8 -> bool
    val mul_unsafe = _builtin val Int_mul_unsafe : int8 * int8 -> int8
    val quot_unsafe = _builtin val Int_quot_unsafe : int8 * int8 -> int8
    val rem_unsafe = _builtin val Int_rem_unsafe : int8 * int8 -> int8
    val sub_unsafe = _builtin val Int_sub_unsafe : int8 * int8 -> int8
    val abs = _builtin val Int_abs : int8 -> int8
    val add = _builtin val Int_add : int8 * int8 -> int8
    val div = _builtin val Int_div : int8 * int8 -> int8
    val mod = _builtin val Int_mod : int8 * int8 -> int8
    val mul = _builtin val Int_mul : int8 * int8 -> int8
    val neg = _builtin val Int_neg : int8 -> int8
    val quot = _builtin val Int_quot : int8 * int8 -> int8
    val rem = _builtin val Int_rem : int8 * int8 -> int8
    val sub = _builtin val Int_sub : int8 * int8 -> int8
    val fromInt32 = _builtin val Int_toInt : int32 -> int8
    val toInt32 = _builtin val Int_toInt : int8 -> int32
  end

  structure Int16 =
  struct
    val add_unsafe = _builtin val Int_add_unsafe : int16 * int16 -> int16
    val gt = _builtin val Int_gt : int16 * int16 -> bool
    val gteq = _builtin val Int_gteq : int16 * int16 -> bool
    val lt = _builtin val Int_lt : int16 * int16 -> bool
    val lteq = _builtin val Int_lteq : int16 * int16 -> bool
    val mul_unsafe = _builtin val Int_mul_unsafe : int16 * int16 -> int16
    val quot_unsafe = _builtin val Int_quot_unsafe : int16 * int16 -> int16
    val rem_unsafe = _builtin val Int_rem_unsafe : int16 * int16 -> int16
    val sub_unsafe = _builtin val Int_sub_unsafe : int16 * int16 -> int16
    val abs = _builtin val Int_abs : int16 -> int16
    val add = _builtin val Int_add : int16 * int16 -> int16
    val div = _builtin val Int_div : int16 * int16 -> int16
    val mod = _builtin val Int_mod : int16 * int16 -> int16
    val mul = _builtin val Int_mul : int16 * int16 -> int16
    val neg = _builtin val Int_neg : int16 -> int16
    val quot = _builtin val Int_quot : int16 * int16 -> int16
    val rem = _builtin val Int_rem : int16 * int16 -> int16
    val sub = _builtin val Int_sub : int16 * int16 -> int16
    val fromInt32 = _builtin val Int_toInt : int32 -> int16
    val toInt32 = _builtin val Int_toInt : int16 -> int32
  end

  structure Int32 =
  struct
    val add_unsafe = _builtin val Int_add_unsafe : int32 * int32 -> int32
    val gt = _builtin val Int_gt : int32 * int32 -> bool
    val gteq = _builtin val Int_gteq : int32 * int32 -> bool
    val lt = _builtin val Int_lt : int32 * int32 -> bool
    val lteq = _builtin val Int_lteq : int32 * int32 -> bool
    val mul_unsafe = _builtin val Int_mul_unsafe : int32 * int32 -> int32
    val quot_unsafe = _builtin val Int_quot_unsafe : int32 * int32 -> int32
    val rem_unsafe = _builtin val Int_rem_unsafe : int32 * int32 -> int32
    val sub_unsafe = _builtin val Int_sub_unsafe : int32 * int32 -> int32
    val abs = _builtin val Int_abs : int32 -> int32
    val add = _builtin val Int_add : int32 * int32 -> int32
    val div = _builtin val Int_div : int32 * int32 -> int32
    val mod = _builtin val Int_mod : int32 * int32 -> int32
    val mul = _builtin val Int_mul : int32 * int32 -> int32
    val neg = _builtin val Int_neg : int32 -> int32
    val quot = _builtin val Int_quot : int32 * int32 -> int32
    val rem = _builtin val Int_rem : int32 * int32 -> int32
    val sub = _builtin val Int_sub : int32 * int32 -> int32
  end

  structure Int64 =
  struct
    val add_unsafe = _builtin val Int_add_unsafe : int64 * int64 -> int64
    val gt = _builtin val Int_gt : int64 * int64 -> bool
    val gteq = _builtin val Int_gteq : int64 * int64 -> bool
    val lt = _builtin val Int_lt : int64 * int64 -> bool
    val lteq = _builtin val Int_lteq : int64 * int64 -> bool
    val mul_unsafe = _builtin val Int_mul_unsafe : int64 * int64 -> int64
    val quot_unsafe = _builtin val Int_quot_unsafe : int64 * int64 -> int64
    val rem_unsafe = _builtin val Int_rem_unsafe : int64 * int64 -> int64
    val sub_unsafe = _builtin val Int_sub_unsafe : int64 * int64 -> int64
    val abs = _builtin val Int_abs : int64 -> int64
    val add = _builtin val Int_add : int64 * int64 -> int64
    val div = _builtin val Int_div : int64 * int64 -> int64
    val mod = _builtin val Int_mod : int64 * int64 -> int64
    val mul = _builtin val Int_mul : int64 * int64 -> int64
    val neg = _builtin val Int_neg : int64 -> int64
    val quot = _builtin val Int_quot : int64 * int64 -> int64
    val rem = _builtin val Int_rem : int64 * int64 -> int64
    val sub = _builtin val Int_sub : int64 * int64 -> int64
    val fromInt32 = _builtin val Int_toInt : int32 -> int64
    val toInt32 = _builtin val Int_toInt : int64 -> int32
  end

  structure Word8 =
  struct
    val add = _builtin val Word_add : word8 * word8 -> word8
    val andb = _builtin val Word_andb : word8 * word8 -> word8
    val arshift_unsafe =
        _builtin val Word_arshift_unsafe : word8 * word8 -> word8
    val div_unsafe = _builtin val Word_div_unsafe : word8 * word8 -> word8
    val gt = _builtin val Word_gt : word8 * word8 -> bool
    val gteq = _builtin val Word_gteq : word8 * word8 -> bool
    val lshift_unsafe =
        _builtin val Word_lshift_unsafe : word8 * word8 -> word8
    val lt = _builtin val Word_lt : word8 * word8 -> bool
    val lteq = _builtin val Word_lteq : word8 * word8 -> bool
    val mod_unsafe = _builtin val Word_mod_unsafe : word8 * word8 -> word8
    val mul = _builtin val Word_mul : word8 * word8 -> word8
    val orb = _builtin val Word_orb : word8 * word8 -> word8
    val rshift_unsafe =
        _builtin val Word_rshift_unsafe : word8 * word8 -> word8
    val sub = _builtin val Word_sub : word8 * word8 -> word8
    val xorb = _builtin val Word_xorb : word8 * word8 -> word8
    val arshift = _builtin val Word_arshift : word8 * word32 -> word8
    val div = _builtin val Word_div : word8 * word8 -> word8
    val lshift = _builtin val Word_lshift : word8 * word32 -> word8
    val mod = _builtin val Word_mod : word8 * word8 -> word8
    val neg = _builtin val Word_neg : word8 -> word8
    val notb = _builtin val Word_notb : word8 -> word8
    val rshift = _builtin val Word_rshift : word8 * word32 -> word8
    val toWord16 = _builtin val Word_zext_trunc : word8 -> word16
    val toWord16X = _builtin val Word_sext_trunc : word8 -> word16
    val toWord32 = _builtin val Word_zext_trunc : word8 -> word32
    val toWord32X = _builtin val Word_sext_trunc : word8 -> word32
    val toWord64 = _builtin val Word_zext_trunc : word8 -> word64
    val toWord64X = _builtin val Word_sext_trunc : word8 -> word64
    val fromInt8 = _builtin val TypeCast : int8 -> word8
    val toInt8X = _builtin val TypeCast : word8 -> int8
    val fromInt32 = _builtin val Word_fromInt : int32 -> word8
    val toInt32 = _builtin val Word_toInt : word8 -> int32
    val toInt32X = _builtin val Word_toIntX : word8 -> int32
    val castToChar = _builtin val TypeCast : word8 -> char
  end

  structure Word16 =
  struct
    val add = _builtin val Word_add : word16 * word16 -> word16
    val andb = _builtin val Word_andb : word16 * word16 -> word16
    val arshift_unsafe =
        _builtin val Word_arshift_unsafe : word16 * word16 -> word16
    val div_unsafe = _builtin val Word_div_unsafe : word16 * word16 -> word16
    val gt = _builtin val Word_gt : word16 * word16 -> bool
    val gteq = _builtin val Word_gteq : word16 * word16 -> bool
    val lshift_unsafe =
        _builtin val Word_lshift_unsafe : word16 * word16 -> word16
    val lt = _builtin val Word_lt : word16 * word16 -> bool
    val lteq = _builtin val Word_lteq : word16 * word16 -> bool
    val mod_unsafe = _builtin val Word_mod_unsafe : word16 * word16 -> word16
    val mul = _builtin val Word_mul : word16 * word16 -> word16
    val orb = _builtin val Word_orb : word16 * word16 -> word16
    val rshift_unsafe =
        _builtin val Word_rshift_unsafe : word16 * word16 -> word16
    val sub = _builtin val Word_sub : word16 * word16 -> word16
    val xorb = _builtin val Word_xorb: word16 * word16 -> word16
    val arshift = _builtin val Word_arshift : word16 * word32 -> word16
    val div = _builtin val Word_div : word16 * word16 -> word16
    val lshift = _builtin val Word_lshift : word16 * word32 -> word16
    val mod = _builtin val Word_mod : word16 * word16 -> word16
    val neg = _builtin val Word_neg : word16 -> word16
    val notb = _builtin val Word_notb : word16 -> word16
    val rshift = _builtin val Word_rshift : word16 * word32 -> word16
    val toWord8 = _builtin val Word_zext_trunc : word16 -> word8
    val toWord32 = _builtin val Word_zext_trunc : word16 -> word32
    val toWord32X = _builtin val Word_sext_trunc : word16 -> word32
    val toWord64 = _builtin val Word_zext_trunc : word16 -> word64
    val toWord64X = _builtin val Word_sext_trunc : word16 -> word64
    val fromInt16 = _builtin val TypeCast : int16 -> word16
    val toInt16X = _builtin val TypeCast : word16 -> int16
    val fromInt32 = _builtin val Word_fromInt : int32 -> word16
    val toInt32 = _builtin val Word_toInt : word16 -> int32
    val toInt32X = _builtin val Word_toIntX : word16 -> int32
  end

  structure Word32 =
  struct
    val add = _builtin val Word_add : word32 * word32 -> word32
    val andb = _builtin val Word_andb : word32 * word32 -> word32
    val arshift_unsafe =
        _builtin val Word_arshift_unsafe : word32 * word32 -> word32
    val div_unsafe = _builtin val Word_div_unsafe : word32 * word32 -> word32
    val gt = _builtin val Word_gt : word32 * word32 -> bool
    val gteq = _builtin val Word_gteq : word32 * word32 -> bool
    val lshift_unsafe =
        _builtin val Word_lshift_unsafe : word32 * word32 -> word32
    val lt = _builtin val Word_lt : word32 * word32 -> bool
    val lteq = _builtin val Word_lteq : word32 * word32 -> bool
    val mod_unsafe = _builtin val Word_mod_unsafe : word32 * word32 -> word32
    val mul = _builtin val Word_mul : word32 * word32 -> word32
    val orb = _builtin val Word_orb : word32 * word32 -> word32
    val rshift_unsafe =
        _builtin val Word_rshift_unsafe : word32 * word32 -> word32
    val sub = _builtin val Word_sub : word32 * word32 -> word32
    val xorb = _builtin val Word_xorb : word32 * word32 -> word32
    val arshift = _builtin val Word_arshift : word32 * word32 -> word32
    val div = _builtin val Word_div : word32 * word32 -> word32
    val fromInt = _builtin val TypeCast : int32 -> word32
    val lshift = _builtin val Word_lshift : word32 * word32 -> word32
    val mod = _builtin val Word_mod : word32 * word32 -> word32
    val neg = _builtin val Word_neg : word32 -> word32
    val notb = _builtin val Word_notb : word32 -> word32
    val rshift = _builtin val Word_rshift : word32 * word32 -> word32
    val toWord8 = _builtin val Word_zext_trunc : word32 -> word8
    val toWord16 = _builtin val Word_zext_trunc : word32 -> word16
    val toWord64 = _builtin val Word_zext_trunc : word32 -> word64
    val toWord64X = _builtin val Word_sext_trunc : word32 -> word64
    val fromInt32 = _builtin val TypeCast : int32 -> word32
    val toInt32 = _builtin val Word_toInt : word32 -> int32
    val toInt32X = _builtin val TypeCast : word32 -> int32
  end

  structure Word64 =
  struct
    val add = _builtin val Word_add : word64 * word64 -> word64
    val andb = _builtin val Word_andb : word64 * word64 -> word64
    val arshift_unsafe =
        _builtin val Word_arshift_unsafe : word64 * word64 -> word64
    val div_unsafe = _builtin val Word_div_unsafe : word64 * word64 -> word64
    val gt = _builtin val Word_gt : word64 * word64 -> bool
    val gteq = _builtin val Word_gteq : word64 * word64 -> bool
    val lshift_unsafe =
        _builtin val Word_lshift_unsafe : word64 * word64 -> word64
    val lt = _builtin val Word_lt : word64 * word64 -> bool
    val lteq = _builtin val Word_lteq : word64 * word64 -> bool
    val mod_unsafe = _builtin val Word_mod_unsafe : word64 * word64 -> word64
    val mul = _builtin val Word_mul : word64 * word64 -> word64
    val orb = _builtin val Word_orb : word64 * word64 -> word64
    val rshift_unsafe =
        _builtin val Word_rshift_unsafe : word64 * word64 -> word64
    val sub = _builtin val Word_sub : word64 * word64 -> word64
    val xorb = _builtin val Word_xorb : word64 * word64 -> word64
    val arshift = _builtin val Word_arshift : word64 * word32 -> word64
    val div = _builtin val Word_div : word64 * word64 -> word64
    val fromInt = _builtin val Word_fromInt : int32 -> word64
    val lshift = _builtin val Word_lshift : word64 * word32 -> word64
    val mod = _builtin val Word_mod : word64 * word64 -> word64
    val neg = _builtin val Word_neg : word64 -> word64
    val notb = _builtin val Word_notb : word64 -> word64
    val rshift = _builtin val Word_rshift : word64 * word32 -> word64
    val toWord8 = _builtin val Word_zext_trunc : word64 -> word8
    val toWord16 = _builtin val Word_zext_trunc : word64 -> word16
    val toWord32 = _builtin val Word_zext_trunc : word64 -> word32
    val toInt64X = _builtin val TypeCast : word64 -> int64
    val fromInt64 = _builtin val TypeCast : int64 -> word64
    val fromInt32 = _builtin val Word_fromInt : int32 -> word64
    val toInt32 = _builtin val Word_toInt : word64 -> int32
    val toInt32X = _builtin val Word_toIntX : word64 -> int32
  end

  structure General =
  struct
    datatype exntag = _builtin datatype exntag
    (* see also EmitTypedLambda.sml *)
    val exnImpl = _builtin val TypeCast : exn -> exntag * string
    val exntagImpl = _builtin val TypeCast : exntag -> (string * word32) vector
    val exnToBoxed = _builtin val TypeCast : exn -> boxed
    val := = _builtin val Ref_assign : 'a ref * 'a -> unit
    val ! = _builtin val Ref_deref : 'a ref -> 'a
    val o = _builtin val Compose : ('a -> 'b) * ('c -> 'a) -> ('c -> 'b)
    val before = _builtin val Before : 'a * unit -> 'a
    val ignore = _builtin val Ignore : 'a -> unit
  end

  structure Pointer =
  struct
    val identityEqual = _builtin val IdentityEqual : boxed * boxed -> bool
    val advance = _builtin val Ptr_advance : 'a ptr * int32 -> 'a ptr
    val deref = _builtin val Ptr_deref : 'a ptr -> 'a
    val store = _builtin val Ptr_store : 'a ptr * 'a -> unit
    val fromWord64 = _builtin val Ptr_fromWord : word64 -> 'a ptr
    val toWord64 = _builtin val Ptr_toWord : 'a ptr -> word64

    val null = _builtin val Ptr_null : unit -> 'a ptr
    val nullBoxed = _builtin val Boxed_null : unit -> boxed

    val toUnitPtr = _builtin val TypeCast : 'a ptr -> unit ptr
    val fromUnitPtr = _builtin val TypeCast : unit ptr -> 'a ptr
    val toCodeptr = _builtin val BitCast : unit ptr -> codeptr

    val refToBoxed = _builtin val TypeCast : 'a ref -> boxed
    val boxedToRef = _builtin val TypeCast : boxed -> 'a ref

    val castFromBoxed = _builtin val TypeCast : ['a#boxed. boxed -> 'a]
    val castToWord64 = _builtin val TypeCast : boxed -> word64
    val castToBoxed = _builtin val TypeCast : ['a#boxed. 'a -> boxed]

    val boxedToArray = _builtin val TypeCast : boxed -> 'a array
    val boxedToList = _builtin val TypeCast : boxed -> 'a list

    val unitPtrToBoxed = _builtin val TypeCast : unit ptr -> boxed

    val keepAlive = _builtin val KeepAlive : ['a#boxed. 'a -> unit]
  end

  structure Dynamic =
  struct
    val readInt8 = _builtin val Boxed_deref : boxed * word32 -> int8
    val readInt16 = _builtin val Boxed_deref : boxed * word32 -> int16
    val readInt32 = _builtin val Boxed_deref : boxed * word32 -> int32
    val readInt64 = _builtin val Boxed_deref : boxed * word32 -> int64
    val readChar = _builtin val Boxed_deref : boxed * word32 -> char
    val readWord8 = _builtin val Boxed_deref : boxed * word32 -> word8
    val readWord16 = _builtin val Boxed_deref : boxed * word32 -> word16
    val readWord32 = _builtin val Boxed_deref : boxed * word32 -> word32
    val readWord64 = _builtin val Boxed_deref : boxed * word32 -> word64
    val readReal32 = _builtin val Boxed_deref : boxed * word32 -> real32
    val readReal64 = _builtin val Boxed_deref : boxed * word32 -> real64
    val readBoxed = _builtin val Boxed_deref : boxed * word32 -> boxed
    val readPtr = _builtin val Boxed_deref : boxed * word32 -> unit ptr
    val readIntInf = _builtin val Boxed_deref : boxed * word32 -> intInf
    val readString = _builtin val Boxed_deref : boxed * word32 -> string
    val readExn = _builtin val Boxed_deref : boxed * word32 -> exn

    val writeInt8 = _builtin val Boxed_store : boxed * word32 * int8 -> unit
    val writeInt16 = _builtin val Boxed_store : boxed * word32 * int16 -> unit
    val writeInt32 = _builtin val Boxed_store : boxed * word32 * int32 -> unit
    val writeInt64 = _builtin val Boxed_store : boxed * word32 * int64 -> unit
    val writeChar = _builtin val Boxed_store : boxed * word32 * char -> unit
    val writeWord8 = _builtin val Boxed_store : boxed * word32 * word8 -> unit
    val writeWord16 = _builtin val Boxed_store : boxed * word32 * word16 -> unit
    val writeWord32 = _builtin val Boxed_store : boxed * word32 * word32 -> unit
    val writeWord64 = _builtin val Boxed_store : boxed * word32 * word64 -> unit
    val writeReal32 = _builtin val Boxed_store : boxed * word32 * real32 -> unit
    val writeReal64 = _builtin val Boxed_store : boxed * word32 * real64 -> unit
    val writeBoxed = _builtin val Boxed_store : boxed * word32 * boxed -> unit

    val objectSize = _builtin val ObjectSize : boxed -> word32

    val allocRecord =
        _builtin val Record_alloc_unsafe
        : word32 * word32 -> boxed
        (* payloadSize * allocSize (except for header) *)
    val copy =
        _builtin val Boxed_copy
        : boxed * word32 * boxed * word32 * word32 * word32 -> unit
        (* dst * dstIndex * src * srcIndex * size * tag *)
        (* tag = 1 => src is ptr.
         * tag = 0 => src is not ptr. *)

    val sizeToWord = _builtin val Word_zext_trunc : 'a size -> word32
  end

end

datatype int      = _builtin datatype int32
datatype word     = _builtin datatype word32
datatype real     = _builtin datatype real64
